package com.tian.arch.function.permission

import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment


/**
 *  权限申请入口
 *
 *
 *  使用方式
 *  ```
 *    PermissionManager.with(this@AnimationTestActivity)
 *         .permissions(Manifest.permission.CAMERA, Manifest.permission.ACCESS_FINE_LOCATION)
 *         .onGranted {
 *             ...
 *         }
 *         .start()
 *  ```
 *
 */
object PermissionManager {

    private var request: PermissionRequest? = null

    fun with(activity: AppCompatActivity): PermissionRequest {
        val req = ActivityPermissionRequest(activity)
        request = req
        return req
    }

    fun with(fragment: Fragment): PermissionRequest {
        val req = FragmentPermissionRequest(fragment)
        request = req
        return req
    }

    fun onRequestPermissionResult(result: Map<String, Boolean>): Boolean {
        return request?.handleReqPermissionResult(result) == true
    }

    fun cleanPermissionReq() {
        request = null
    }
}



